#define DEBUG
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

const int maxn=5, maxm=200000, inf=0x7ffffff, maxbsize=448;

int min(int a, int b) {
  return a<b ? a : b;
}

void solve(int a, int b, int n, int m, int map[][maxn+1], int dis[][maxn+1]) {
  const int fx[3][2]={{-1, 0}, {0, 1}, {1, 0}};
  static int que[maxn*maxm+1][2];
  static bool book[maxm+1][maxn+1];
  for (int i=1; i<=m; i++) {
    for (int j=1; j<=n; j++) {
      dis[i][j] = inf;
    }
  }
  que[1][0] = a, que[1][1] = b;
  dis[b][a] = 0;
  book[b][a] = true;
  for (int h=0, t=1; h<t; ) {
    h++;
    int x=que[h][0], y=que[h][1];
    book[y][x] = false;
    for (int i=0; i<3; i++) {
      int nx=x+fx[i][0], ny=y+fx[i][1];
      if (nx>0 && ny>0 && nx<=n && ny<=m && map[ny][nx] && dis[ny][nx]>dis[y][x]+1) {
	dis[ny][nx] = dis[y][x]+1;
	if (!book[ny][nx]) {
	  t++;
	  que[t][0] = nx, que[t][1] = ny;
	}
      }
    }
  }
}

void update_Block(int l, int r, int n, int map[][maxn+1], int dis[maxn+1][maxn+1]) {
    static int temp[maxm+1][maxn+1];
    for (int j=1; j<=n; j++) {
      solve(j, 1, n, r-l+1, map, temp);
      for (int k=1; k<=n; k++) {
	dis[j][k] = temp[r-l+1][k];
      }
    }
}

int main() {
  freopen("maze.in", "r", stdin);
  freopen("maze.out", "w", stdout);
  
  static int map[maxm+1][maxn+1], dis[maxm/maxbsize+2][maxn+1][maxn+1];
  int q, n, m, bsize;
  scanf("%d %d %d", &n, &m, &q);
  bsize=ceil(sqrt(m));
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=m; j++) {
      scanf("%d", &map[j][i]);
    }
  }

  for (int i=1; i<=m; i+=bsize) {
    int r=min(i+bsize-1, n);
    update_Block(i/bsize+1, r, n, map+i-1, dis[i/bsize+1]);
  }
  
  for (int i=1; i<=q; i++) {
    int opt;
    scanf("%d", &opt);
    if (opt==1) {
    }
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
